<style type="text/css">
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="110">
        <Form-item label="子系统名称" prop="Subsysname">
            <i-input v-model="formValidate.Subsysname" placeholder="请输入子系统名称"></i-input>
        </Form-item>
        <Form-item label="开门时长" prop="OpenTime">
            <i-input v-model="formValidate.OpenTime" placeholder="请输入门开门时长"></i-input>
        </Form-item>
        <Form-item label="开门间隔时间" prop="Sametime">
            <i-input v-model="formValidate.Sametime" placeholder="请输入开门间隔时间"></i-input>
        </Form-item>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" @click="jumpPage()" style="margin-left: 8px">返回</i-button>
        </Form-item>
    </i-form>
</template>
<script>

    import apiUtil from '../../assets/utils/api_util';
    import baseUtil from '../../assets/utils/base-util'

    export default {
        data() {
            return {
                formValidate: {
                    Subsysname: '',
                    Sametime: '',
                    OpenTime: '',
                },
                ruleValidate: {
                },
                gateId:'',
                subId:'',
                detailData:'',
            }
        },
        mounted: function () {
            this.gateId = this.$route.query.id;
            this.subId = this.$route.query.subId;
            this.getDetail();
        },

        methods: {
            //跳转
            jumpPage: function (id, url) {
                this.$router.back(-1)

            },
            //添加
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.addData(model);
                })
            },
            addData: function (model) {
                let that = this;

                model.id = this.subId;
                model.Forgateid = this.gateId;
                let params = that.$qs.stringify(model);
                this.$Loading.start();

                apiUtil.post(that,apiUtil.urls.EditGateSubSys, params, function (res) {
                    that.$Loading.finish();

                    that.$Modal.confirm({
                        title: '操作成功',
                        content: '请选择下一步操作',
                        // okText: '继续添加',
                        cancelText: '返回子系统列表',
                        onOk: () => {
                            // baseUtil.pageJump(that,'','GateServerAdd')
                        },
                        onCancel: () => {
                            baseUtil.pageJump(that,that.$route.query.id,'GateSubList')

                        }
                    });
                });
            },
            getDetail:function () {
                let that = this;
                let tableData;
                let para = {
                    gateid: that.$route.query.id,
                };
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that,apiUtil.urls.GateSubSysList, para, function (res) {
                    that.$Loading.finish();

                    tableData =res.Msg;

                    that.detailData =tableData[that.$route.query.index];

                    that.formValidate.Subsysname =that.detailData.Subsysname;
                    that.formValidate.OpenTime =that.detailData.Opentime;
                    that.formValidate.Sametime =that.detailData.Sametime;

                    console.log('tableData:', tableData);
                    console.log('detailData:', that.detailData)

                });
            }

        }
    }
</script>
